package com.dw.best_base

import android.Manifest
import android.os.Bundle
import com.loper7.base.ui.BestWebActivity
import com.loper7.base.widget.prcturebrows.ImageBrowser
import com.rxmvp.basemvp.BaseMvpActivity
import com.tbruyelle.rxpermissions2.RxPermissions
import com.tencent.smtt.sdk.TbsVideo
import kotlinx.android.synthetic.main.activity_main.*


/**
 * @author LOPER7
 * @date 2018/12/11 16:50
 * @Description:
 */
class MainActivity : BaseMvpActivity<MainCollection.View, MainCollection.Presenter>(), MainCollection.View {


    override fun getContentViewId(): Int {
        return R.layout.activity_main
    }

    override fun initData() {

    }

    override fun initView() {

        RxPermissions(this)
                .requestEach(Manifest.permission.READ_PHONE_STATE,
                        Manifest.permission.WRITE_EXTERNAL_STORAGE)
                .subscribe { permission ->
                    when {
                        permission.granted -> {
                        }
                        permission.shouldShowRequestPermissionRationale -> // 用户拒绝了该权限，没有选中『不再询问』（Never ask again）,那么下次再次启动时，还会提示请求权限的对话框
                            showWarningMessage("您拒绝了必要权限，请前往设置->应用 打开权限")
                        else -> // 用户拒绝了该权限，并且选中『不再询问』
                            showWarningMessage("您拒绝了必要权限，请前往设置->应用 打开权限")
                    }
                }

        presenter.getData()

    }

    override fun initListener() {

        button_toast.setOnClickListener {
            backHelper.forward(ToastActivity::class.java)
        }
        button_loading.setOnClickListener {
            backHelper.forward(LoadingActivity::class.java)
        }
        button_webView.setOnClickListener {
            BestWebActivity.Builder(backHelper)
                    .setUrl("http://192.168.1.62:8888/mod1.html/#/index")
                    .start()
        }
        button_video.setOnClickListener {
            if (TbsVideo.canUseTbsPlayer(context)) {
                var bundle = Bundle()
                bundle.putInt("screenMode", 104) //从102开始【102：没有横屏、菜单选项；103：默认横屏；104：竖屏；不传：隐藏所有按钮】
                TbsVideo.openVideo(context, "https://vd3.bdstatic.com/mda-ibnw7j0piz0agzi5/sc/mda-ibnw7j0piz0agzi5.mp4", bundle)
            }
        }

        button_image_browse.setOnClickListener {
            var list = arrayListOf<Any>()
            list.add("https://imgsa.baidu.com/forum/w%3D580/sign=5bd8c58a8b18367aad897fd51e728b68/071304adcbef7609a0bf913c23dda3cc7ed99ec0.jpg")
            list.add("https://imgsa.baidu.com/forum/w%3D580/sign=835a59ab01d79123e0e0947c9d355917/dd6fe13f8794a4c234c4ee8803f41bd5af6e3990.jpg")
            list.add("https://imgsa.baidu.com/forum/w%3D580/sign=f916404a801001e94e3c1407880f7b06/a0ffa22bd40735fabc17471a93510fb30d240890.jpg")
            list.add("https://imgsa.baidu.com/forum/w%3D580/sign=a8cdb6907e8da9774e2f86238050f872/9c3a9444ad34598250ea903101f431adcaef841c.jpg")
            list.add("http://imgsrc.baidu.com/forum/pic/item/aaa398345982b2b733ff4c673cadcbef77099b1c.jpg")
            list.add("http://imgsrc.baidu.com/forum/pic/item/0cef1d381f30e924cf6cf19241086e061f95f7b4.jpg")
            list.add("http://imgsrc.baidu.com/forum/pic/item/1a389cec8a136327e525af909c8fa0ec0afac7b4.jpg")
            list.add("http://imgsrc.baidu.com/forum/pic/item/b5ee5e63f6246b60967ee5d7e6f81a4c500fa20c.jpg")
            list.add("http://imgsrc.baidu.com/forum/pic/item/773eb81001e93901ef72da9d76ec54e737d1960c.jpg")
            list.add("http://imgsrc.baidu.com/forum/pic/item/9765e458ccbf6c817c477b4bb13eb13532fa400c.jpg")


            ImageBrowser<Any>(context).setDatas(list).show(0)
        }
    }

    override fun initPresenter(): MainCollection.Presenter {
        return MainCollection.Presenter()
    }

}

